package com.ktwlsoft.archivemanage.domain.business.repositoryService;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ktwlsoft.archivemanage.domain.dao.entity.Question;
import com.ktwlsoft.archivemanage.domain.dao.entity.QuestionDic;
import com.ktwlsoft.archivemanage.domain.dao.repository.QuestionDicMapper;
import com.ktwlsoft.archivemanage.domain.dao.repository.QuestionMapper;
import com.ktwlsoft.archivemanage.payload.question.RelatedQuestionRequest;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Joker
 * @version 1.0
 */
@Service
public class QuestionDicRepositoryService {
    @Getter
    private final QuestionDicMapper questionDicMapper;
    private final QuestionMapper questionMapper;


    public QuestionDicRepositoryService(QuestionDicMapper questionDicMapper, QuestionMapper questionMapper) {
        this.questionDicMapper = questionDicMapper;
        this.questionMapper = questionMapper;
    }

    /**
     * 问题字典查询分页
     *
     * @param pn       第几页
     * @param pageSize 每页多少条
     * @return PageInfo<InstructionDic>
     */
    public PageInfo<QuestionDic> findPage(int pn, int pageSize, String businessFrom) {
        PageHelper.startPage(pn, pageSize);
        PageInfo<QuestionDic> pageInfo = new PageInfo<QuestionDic>(questionDicMapper.selectByBusinessFrom(businessFrom));
        return pageInfo;
    }

    /**
     * 根据问题字典ID查询信息
     *
     * @param id 主键
     * @return MessageManage
     */
    public QuestionDic getById(Long id) {
        return questionDicMapper.selectByPrimaryKey(id);
    }

    /**
     * 问题字典新增
     *
     * @param questionDic
     * @return int
     */
    public int insert(QuestionDic questionDic) {
        return questionDicMapper.insert(questionDic);
    }

    /**
     * 问题字典修改
     *
     * @param questionDic
     * @return int
     */
    public int update(QuestionDic questionDic) {
        return questionDicMapper.updateByPrimaryKey(questionDic);
    }

    /**
     * 根据问题字典id删除信息
     *
     * @param id id
     * @return int
     */
    public int deleteById(Long id) {
        return questionDicMapper.deleteByPrimaryKey(id);
    }

    /**
     * 根据问题字典名查询信息
     *
     * @param questionDic
     * @return QuestionDic
     */
    public List<QuestionDic> getByName(QuestionDic questionDic) {
        return questionDicMapper.getByName(questionDic);
    }

    /**
     * 问题字典下问列表查询
     *
     * @param request
     * @return PageInfo<Question>
     */
    public PageInfo<Question> getByCategoryId(RelatedQuestionRequest request) {
        PageHelper.startPage(request.getPn(), request.getPageSize());
        PageInfo<Question> pageInfo = new PageInfo<Question>(questionMapper.getByCategoryId(request));
        return pageInfo;
    }
}